#include "Metgine/Core/Log.hpp"

#include <iostream>


namespace Metgine
{

namespace Core
{

Log::Log()
{
    //ctor
}

Log::~Log()
{
    Close();
}

void Log::Open(const std::string& path)
{
    #ifdef LOGGING_ENABLED
        m_writer.Open(path);
    #endif
}

void Log::Close()
{

    m_writer.Close();

}

void Log::Write(LogType::LogType type, const char* format, ...)
{

    va_list args;
    va_start(args, format);

    Write(type, format, args);

    va_end(args);

}

void Log::Write(LogType::LogType type, const char* format, va_list args)
{

    #ifdef LOGGING_ENABLED

        const char* lineFormat;
        if (type == LogType::Error)
            lineFormat = "ERROR: ";
        else if (type == LogType::Warning)
            lineFormat = "WARNING: ";
        else
            lineFormat = "";

        vsprintf(m_buffer, format, args);

        m_writer.WriteLine(_T("%s%s"), lineFormat, m_buffer);

        std::cout << lineFormat << m_buffer << std::endl;
    #endif

}

}; // Core
}; // Metgine
